<template>
    <el-dialog width="500px" title="设置押金" :visible.sync="dialogVisible" :close-on-click-modal="false">
      <el-form ref="ruleForm" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="押金金额">
          <el-input v-model="form.money" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { setMoney } from '@/api/order'
  export default {
    // props: ['orderId'],
    props: {
      orderId: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        form: {
            money: '',
            id:''
        },
        rules: {
            money: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        },
        dialogVisible: false
      }
    },
    watch: {
      dialogVisible(val) {
        if (val) {
          this.form.id = this.orderId
          this.form.money = ''
        } else {
          this.$refs['ruleForm'].resetFields()
        }
      }
    },
    methods: {
      submit() {
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            this.form.id = this.orderId
            setMoney({ ...this.form }).then(res => {
              this.dialogVisible = false
              this.$emit('getList', true)
            })
          } else {
            this.$message({
              message: '请检查表单错误',
              type: 'error'
            })
            return false
          }
        })
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  </style>
  